package myservice.android.utilities;

import myservice.android.activities.BaseSaveableActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;

/**
 * Listener for all Spinner views that sets the activity as unsaved when an item is selected.
 */
public class SpinnerMonitor implements OnItemSelectedListener {
	
	private BaseSaveableActivity activity;
	private boolean firstRun = true; // need to catch the first call, because that is invoked by the layout, not user
	
	public SpinnerMonitor(BaseSaveableActivity activity) {
		this.activity = activity;
	}	

	@Override
	public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		if (firstRun) {
			firstRun = false;
			return;
		} else
			activity.activityContentModified = true;
	}

	@Override
	public void onNothingSelected(AdapterView<?> arg0) { }

}
